package com.siyuanren.gcocp.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.util
 * Date         2018/4/18
 * Time         9:38
 * Description
 */
public class ObjectUtil {

    /**
     * 判断Integer 是否为空
     * @param integer
     * @return
     */
    public static boolean isEmpty(Integer integer) {
        if (integer != null && integer != 0) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 拷贝父类的list属性到子类list中
     * @param srcList  需要拷贝的父类list
     * @param tClass   子类class
     * @param <T>
     * @return  子类的list
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static  <T> List<T> convertToChilds(List<?> srcList, Class<T> tClass) throws IllegalAccessException, InstantiationException {
        if (srcList == null || tClass == null) {
            return null;
        }

        List<T> list = new ArrayList<>(srcList.size());
        for (Object src : srcList) {
            T dest = tClass.newInstance();
            BeanUtils.copyProperties(src, dest);
            list.add(dest);
        }
        return list;
    }
}
